package com.example.sunsg.okhttptest.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.breadtrip.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by NOTE-026 on 2016/5/10.
 */
public class RecyclerViewItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private LayoutInflater mInflater;
    private List<String> mItmes;
    public RecyclerViewItemAdapter(Context context) {
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
        mItmes = new ArrayList<>();
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_activity_recycler_view,parent,false);
        StringHolder holder = new StringHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        String entry = (String) getItem(position);
        StringHolder stringHolder = (StringHolder) holder;
        stringHolder.tvName.setText(entry);
    }

    @Override
    public int getItemCount() {
        return mItmes == null ? 0 : mItmes.size();
    }

    private Object getItem(int position){
        return mItmes.get(position);
    }

    public void setItem(List<String> items){
        this.mItmes = items;
        notifyDataSetChanged();
    }


    /***
     * layout item_activity_recycler_view
     */
    public static class StringHolder extends RecyclerView.ViewHolder{
        public TextView tvName;
        public RecyclerView recyclerView;
        public StringHolder(View itemView) {
            super(itemView);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
//            recyclerView = (RecyclerView) itemView.findViewById(R.id.recycle_view_item);
//            recyclerView.setVisibility(View.GONE);
        }
    }
}
